package com.zero.dubbo.sample.echo;


import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.zero.dubbo.sample.api.EchoService;


public class EchoCustomer {

    public static void main(String[] args) {

        //当前应用配置
        ApplicationConfig applicationConfig = new ApplicationConfig();
        applicationConfig.setName("java-echo-customer");
        applicationConfig.setVersion("1.0.0");
        applicationConfig.setOwner("wql");

        //连接注册中心
        RegistryConfig registryConfig = new RegistryConfig("zookeeper://192.168.0.239:2181");

        //引用远程服务
        // 此实例很重，封装了与注册中心的连接以及与提供者的连接，请自行缓存，否则可能造成内存和连接泄漏
        ReferenceConfig<EchoService> reference = new ReferenceConfig<>();
        reference.setApplication(applicationConfig);
        reference.setRegistry(registryConfig);
        reference.setInterface(EchoService.class);
        // 注意：此代理对象内部封装了所有通讯细节，对象较重，请缓存复用
        EchoService echoService = reference.get();
        String message = echoService.echo("Hello world");
        System.out.println(message);
    }
}
